package com.aiju.widgit;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import com.aiju.common.PixValue;

/**
 * @author: 佐为
 * @date: 2017-03-27 17:38
 * @version: V1.0
 * @Description: 描述
 */
public class ColorView extends View {

    public void setColor(String color) {
        this.color = color;
        invalidate();
    }

    private String color;


    public ColorView(Context context) {
        super(context);
        init();
    }

    public ColorView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        color = "#3396ff";
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int verticalCenter = getHeight() / 2;
        int horizontalCenter = getWidth() / 2;
        int circleRadius = PixValue.dp.valueOf(15);

        Paint paint = new Paint();
        if (isSelected()) {
            paint.setAntiAlias(true);
            paint.setColor(Color.BLACK);
            canvas.drawCircle(horizontalCenter, verticalCenter, circleRadius, paint);
        }

        paint.setAntiAlias(true);
        paint.setColor(Color.parseColor(color));
        canvas.drawCircle(horizontalCenter, verticalCenter, circleRadius - PixValue.dp.valueOf(1), paint);
    }
}
